# 3,4
# F,M,M,F
# F,M,M,F
# F,F,F,M
def you(x, y, student):
    if student[x][y] == "M":
        res[0] += 1
    if y + 1 < len(student[0]):
        you(x, y + 1, student)
    else:
        return
    return


def xia(x, y, student):
    if student[x][y] == "M":
        res[1] += 1
    if x + 1 < len(student):
        xia(x + 1, y, student)
    else:
        return
    return


def zheng(x, y, student):
    if student[x][y] == "M":
        res[2] += 1
    if x + 1 < len(student) and y + 1 < len(student[0]):
        zheng(x + 1, y + 1, student)
    else:
        return
    return


def fan(x, y, student):
    if student[x][y] == "M":
        res[3] += 1
    if x - 1 >= 0 and y - 1 >= 0:
        fan(x - 1, y - 1, student)
    else:
        return
    return


res = [0] * 4
list_1 = input().split(",")
m = int(list_1[0])
n = int(list_1[1])
students = []
for i in range(m):
    students.append(input().split(","))
# print(students)
res1 = 0
for i in range(m):
    for j in range(n):
        if students[i][j] == "M":
            you(i, j, students)
            xia(i, j, students)
            zheng(i, j, students)
            fan(i, j, students)
            res1 = max(res1, max(res))
            res = [0] * 4
print(res1)
